package ${rootPath}.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ${rootPath}.model.Result;
import ${rootPath}.model.${entityName};
import ${rootPath}.service.${entityName}Service;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.UUID;

/**
* @描述
* @创建人 wangyue
* @创建时间2019/12/216:25
*/
@Api("restful风格的api示例")
@RestController
@RequestMapping("${entityNameLower}")
public class ${entityName}Controller {

@Autowired
private ${entityName}Service ${entityNameLower}Service;

@ApiOperation(value = "查询列表")
@GetMapping("list")
public Result<${entityName}> list1(HttpServletRequest request, ${entityName} ${entityNameLower},
    @RequestParam(defaultValue = "1") int pagenum,
    @RequestParam(defaultValue = "2") int pagesize){
    PageHelper.startPage(pagenum,pagesize);
    List<${entityName}> ${entityNameLower}List = ${entityNameLower}Service.list(${entityNameLower});
        PageInfo<${entityName}> pageInfo = new PageInfo<>(${entityNameLower}List);
            return new Result(pageInfo.getTotal(),pageInfo.getList());
            }


            @ApiOperation(value = "查询单条")
            @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "用户id",required = true,paramType = "path")})
            @ApiResponses({@ApiResponse(code=400,message="id为空")})
            @GetMapping("getById/{id}")
            public ${entityName} getById(@PathVariable String id){
            return ${entityNameLower}Service.getById(id);
            }


            @ApiOperation(value = "新增修改")
            @PostMapping("save")
            public Boolean save(@RequestBody ${entityName} ${entityNameLower}){
            String id = ${entityNameLower}.getId();
            if(id !=null && !id.equals("")){
            ${entityNameLower}Service.update(${entityNameLower});
            } else{
            ${entityNameLower}.setId(UUID.randomUUID().toString());
            ${entityNameLower}Service.insert(${entityNameLower});
            }
            return true;
            }
            @ApiOperation(value = "删除")
            @DeleteMapping("delete")
            public boolean delete(String ids){
            if(ids != null && !ids.equals("")){
            ${entityNameLower}Service.deletebth(ids.split(","));
            }
            return true;
            }
            }
